//
//  MessageCenterViewController.m
//  carcareIOS
//
//  Created by 王然 on 16/9/1.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "MessageCenterViewController.h"

#import "MessageListNormalViewController.h"
@interface MessageCenterViewController ()

@property (nonatomic , strong) BaseViewModel <MessageCenterViewModelDelegate>* viewModel;

@end

@implementation MessageCenterViewController

- (instancetype)initWithViewModel:(BaseViewModel<MessageCenterViewModelDelegate> *)viewModel
{
    self = [super initWithTableRefreshType:TYPE_TABLE_REFRESH_NONE];
    if (self) {
        self.viewModel = viewModel;
        self.viewModel.viewController = self;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"消息中心";
    [self createTableView];
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.viewModel updateMessageCenterData];
}

- (void)createTableView
{
    self.tableView.frame = CGRectMake(0, 0 , __MAIN_WIDTH , __MAIN_HEIGHT_64);
    self.tableView.backgroundColor = [Theme backGroundColor];
    self.tableView.separatorColor = [Theme lineNewColor];
}
#pragma mark - tableView Delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.viewModel MessageCenterNums];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return [MessageCenterCell getCellHeight];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString * cellID = @"MessageCenterCell";
    MessageCenterCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[MessageCenterCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    [cell reloadDataIcon:(indexPath.row < self.titleArray.count ? self.titleArray[indexPath.row][1] : @"") title:(indexPath.row < self.titleArray.count ? self.titleArray[indexPath.row][0] : @"") model:[self.viewModel messageCenterAtIndex:indexPath.row]];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([Check isVisiter])
    {
        return;
    }
    
    [self.viewModel clickOnMessageCenterAtIndex:indexPath.row];
}
- (NSArray *)titleArray
{
    return @[@[@"车辆消息",@"carMessageIcon"],@[@"服务消息",@"serviceMessageIcon"],@[@"保险消息",@"insuMessageIcon"],@[@"系统消息",@"systemMessageIcon"]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
